package com.ruan.service;

import com.ruan.dao.EmpMapper;
import com.ruan.openfeign.DeptCenterOpenfeign;
import com.ruan.pojo.Dept;
import com.ruan.pojo.Emp;
import com.ruan.query.EmpQuery;
import com.ruan.vo.EmpVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName:EmpService
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/6/14 16:20
 **/
@Service
public class EmpService {

    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private DeptCenterOpenfeign deptCenterOpenfeign;

    public List<EmpVo> getEmpList(EmpQuery empQuery) {

        List<EmpVo> empVoList = empMapper.getEmpList(empQuery);

        for(EmpVo i:empVoList){

            i.setBossName(getEmpNameById(i.getBossId()));

            Dept dept = deptCenterOpenfeign.getDeptById(i.getDeptId());

            i.setDeptName(dept.getDeptName());

            i.setDeptAddress(dept.getDeptAddress());

        }

        return empVoList;

    }

    public String getEmpNameById(Integer id) {

        return empMapper.getEmpNameById(id);

    }
}
